package com.example.panpan.customerManage.controller;

import com.example.common.utils.IMap;
import com.example.common.utils.PageView;
import com.example.common.utils.ReturnMapUtils;
import com.example.common.utils.SessionUtil;
import com.example.panpan.customerManage.service.FeedbackService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class feedbackCon {
    @Autowired
    private FeedbackService feedbackService;
    /**
     * 反馈管理页面
     * */
    @RequestMapping(value = "/feedbackCon/toPage/feedbackManageView")
    public String feedbackManageView(){
        return "/module/feedbackManage/feedbackManage";
    }
    /**
     * 反馈页面
     * */
    @RequestMapping(value = "/feedbackCon/toPage/feedbackAddView")
    public String feedbackAddView(){
        return "/module/feedbackManage/addFeedback";
    }
    /**
     * 获得列表
     * */
    @RequestMapping(value = "/feedbackCon/toPage/getFeedbackList",method = RequestMethod.POST)
    @ResponseBody
    public Map getFeedbackList(HttpServletRequest request){
        IMap params = new IMap(request);
        Page page = PageView.startPageForTable(params, false);
        List<IMap> feedbackList = feedbackService.getFeedbackList(params);
        Map<String, Object> result = PageView.getResultForTable(page, feedbackList);
        return result;
    }

    @RequestMapping(value = "/feedbackCon/ajax/updState",method = RequestMethod.POST)
    @ResponseBody
    public Map updState(HttpServletRequest request){
        IMap params = new IMap(request);
        HttpSession session = request.getSession();
        String userId = SessionUtil.getLoginUserId(session);
        params.put("updateUser",userId);
        int i = feedbackService.updState(params);
        if (i==1){
            return ReturnMapUtils.businessResult("0000","标记成功！");
        }else {
            return ReturnMapUtils.businessResult("9999","服务器错误，操作失败！");
        }
    }

    @RequestMapping(value = "/feedbackCon/ajax/addFeedback",method = RequestMethod.POST)
    @ResponseBody
    public Map addFeedback(HttpServletRequest request){
        IMap params = new IMap(request);
        HttpSession session = request.getSession();
        String userId = SessionUtil.getLoginUserId(session);
        params.put("updateUser",userId);
        int i = feedbackService.addFeedback(params);
        if (i==1){
            return ReturnMapUtils.businessResult("0000","反馈成功！");
        }else {
            return ReturnMapUtils.businessResult("9999","服务器错误，操作失败！");
        }
    }
}
